import { LoadingBar } from 'quasar'
import InterfaceProxy from 'src/utils/mider'
import { defaultOptions, ResponseData } from '../_options'

/**
 * 工具
 * @namespace iMessage
 */

/** @lends iMessage# */
const interfaceOpt = {
  create: {
    name: '新增',
    url: 'p/v1/msg-api/create',
    method: 'post',
    params: {
      data: Object
    },
    beforeSend () {
      LoadingBar.start()
    },
    successHandler (res: ResponseData) {
      LoadingBar.stop()
      return {
        success: res.code === 0,
        data: res.data,
        msg: res.msg
      }
    }
  },
  update: {
    name: '保存/更新内容',
    url: 'p/v1/msg-api/update',
    method: 'post',
    params: {
      data: Object
    }
  },
  delete: {
    name: '删除内容',
    url: 'p/v1/msg-api/delete',
    method: 'post',
    params: {
      data: Object
    }
  },
  pause: {
    name: '删除内容',
    url: 'p/v1/msg-api/pause',
    method: 'post',
    params: {
      data: Object
    }
  },
  getList: {
    url: '/p/v1/msg-api/list',
    method: 'get'
  }
}

/** @mixes iMessage */
const iMessage = new InterfaceProxy(interfaceOpt, [defaultOptions])
export default iMessage
